import {Body, Controller, Delete, Get, Post, Query, Request, UseGuards} from '@nestjs/common';
import {BookmarkService} from './bookmark.service'
import {AuthGuard} from "@nestjs/passport";

@Controller('bookmark')
export class BookmarkController {
    constructor(private readonly bookmarkService: BookmarkService) {
    }

    // 获取书签列表
    @Get()
    booklist(@Query() request) {
        return this.bookmarkService.bookmarkList(request)
    }

    // 创建书签
    @Post()
    @UseGuards(AuthGuard('jwt'))
    createBookmark(@Body() bodyData, @Request() req) {
        const user_id = req.user.id
        return this.bookmarkService.createBookmark({user_id, ...bodyData})
    }

    // 创建书签
    @Post('update')
    @UseGuards(AuthGuard('jwt'))
    updateBookmark(@Body() bodyData, @Request() req) {
        const user_id = req.user.id
        return this.bookmarkService.updateBookmark({user_id, ...bodyData})
    }

    // 删除书签
    @Delete()
    @UseGuards(AuthGuard('jwt'))
    delBookmark(@Query() params) {
        return this.bookmarkService.delBookmark(params)
    }

    // 用户渲染书签列表
    @Get('user')
    getBookmarkList() {
        return this.bookmarkService.getBookmarkList()
    }

    // 书签浏览量+1
    @Get('pv')
    addBookmarkPv(@Query() queryData) {
        return this.bookmarkService.addBookmarkPv(queryData)
    }

    // 书签收藏
    @Get('hoard_tags')
    @UseGuards(AuthGuard('jwt'))
    bookmarkHoard(@Query() queryData, @Request() req) {
        const user_id = req.user.id
        return this.bookmarkService.bookmarkHoard({...queryData, user_id})
    }
}
